<style lang="less">
  .standard-price-version-price-add {

  }
</style>

<template>
  <el-dialog :modal-append-to-body="false" title="新增线路运价" :visible.sync="dialogVisible" size="tiny" class="standard-price-version-price-add">
    <el-form label-width="100px" ref="form" :model="form">
      <el-form-item label="阶梯起始"
                    :rules="{ type: 'number', required: true, message: '请输入阶梯起始', trigger: 'blur' }"
                    prop="startGraded">
        <el-input v-model.number="form.startGraded"></el-input>
      </el-form-item>
      <el-form-item label="阶梯终止"
                    :rules="{ type: 'number', required: true, message: '请输入阶梯终止', trigger: 'blur' }"
                    prop="endGraded">
        <el-input v-model.number="form.endGraded"></el-input>
      </el-form-item>
      <el-form-item label="计费方式" v-if="billingType === 112003001">
        <el-radio-group v-model="form.chargingMode">
          <el-radio :label="112015001">按重量</el-radio>
          <el-radio :label="112015003">按件数</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="计费方式" v-if="billingType === 112003002">
        <el-radio-group v-model="form.chargingMode">
          <el-radio :label="112015002">按体积</el-radio>
          <el-radio :label="112015003">按件数</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="单价"
                    :rules="{ type: 'number', required: true, message: '请输入单价', trigger: 'blur' }"
                    prop="billingUnivalence">
        <el-input v-model.number="form.billingUnivalence"></el-input>
      </el-form-item>
      <el-form-item label="排序"
                    :rules="{ type: 'number', required: true, message: '请输入排序号', trigger: 'blur' }"
                    prop="sort">
        <el-input  v-model.number="form.sort"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="createform" :loading="loading">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'StandardPriceVersionPriceAdd',
  componentName: 'StandardPriceVersionPriceAdd',
  data () {
    return {
      standardPriceVersionId: null,
      dialogVisible: false,
      loading: false,
      form: {
        id: null,
        startGraded: null,
        endGraded: null,
        chargingMode: null,
        billingUnivalence: null,
        sort: null
      }
    };
  },
  props: {
    billingType: Number
  },
  methods: {
    reset: function () {
      if (this.$refs.form) {
        this.$refs.form.resetFields();
      }
      this.$ue.resetObjNull(this.form);
    },
    show (o) {
      this.reset();
      if (o) {
        this.form.id = o.id;
        this.form.startGraded = o.startGraded;
        this.form.endGraded = o.endGraded;
        this.form.chargingMode = o.chargingMode;
        this.form.billingUnivalence = o.billingUnivalence;
        this.form.sort = o.sort;
      } else {
        if (this.billingType === 112003001) {
          this.form.chargingMode = 112015001;
        } else if (this.billingType === 112003002) {
          this.form.chargingMode = 112015002;
        } else {
          this.form.chargingMode = 112015003;
        }
      }
      this.dialogVisible = true;
      this.loading = false;
    },
    hide () {
      this.loading = false;
      this.dialogVisible = false;
    },
    createform () {
      this.$refs.form.validate((valid) => {
        if (valid) {
          let o = Object.assign({}, this.form);
          this.loading = true;
          this.$emit('comfirmSuccess', o);
        }
      });
    }
  },
  mounted () {}
};
</script>
